
<?php
require 'Controller.php ';
require 'Admin/Model/UserModel.php';
class UserController extends Controller{
	function __Construct(){
		parent::__Construct();
	
	}
	function listusers(){
		
		$model = new UserModel();
		$data = $model->getUserList();
		$this->assign('users',$data);
		$this->display(); 
		//return $data;

	}
function deluser(){
			$uid=$_GET['uid'];//根据uid查找要删除的用户
			$model=new UserModel();
			$result=$model->delUser($uid);
			if($result){
				echo "删除成功!3秒后跳转回用户列表页";
				header("refresh:3;url='admin.php?c=user&m=listusers'");//隔3秒跳回

			}
			else{
				echo "删除失败!";
				echo "<a href='admin.php?c=user&m=listusers'>返回列表</a>";
				
			}
		}
function reguser(){
	       $this->display();
}
function adduser(){
	$data=$_POST;
    $file=$_FILES;
    $model=new UserModel();
    $result=$model->adduser($data,$file);
    if ($result) {
    	echo "注册成功，3秒后返回用户列表页。";
    	header("refresh:3;url='admin.php?c=user&m=listusers'");
    }else{
    	echo "注册失败，3秒后返回用户注册页重新注册。";
    	header("refresh:3;url='admin.php?c=user&m=reguser'");
    }

}
function edituser(){
	$uid=$_GET['uid'];
	$model=new UserModel();
	$data=$model->edituser($uid);
    $this->assign('user',$data);
    $this->display();

}
function updateuser(){
	$data=$_POST;
	$file=$_FILES;
	$model=new UserModel();
	$result=$model->updateuser($data,$file);
	if($result){
				echo "修改成功!3秒后跳转回用户列表页";
				header("refresh:3;url='admin.php?c=user&m=listusers'");//隔3秒跳回

			}
			else{
				echo "修改失败!";
				echo "<a href='admin.php?c=user&m=listusers'>返回列表</a>";
				
			}
	}
	
   function searchuser(){
	    $uname=$_POST;
	    $model = new UserModel();
		$data = $model->searchuser($uname);
		$this->assign('user',$data);
		$this->display(); 
	}

}
?>
